<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
   <title>Sample</title>
   <script type="text/javascript" src="https://www.google.com/jsapi"> </script>
   <script type="text/javascript">
      var ge;
      google.load("earth", "1");
      // add a navigation control


      function init() {
         google.earth.createInstance('map3d', initCB, failureCB);
      }

      function initCB(instance) {
         ge = instance;
         ge.getWindow().setVisibility(true);
         
         var i;
         for( i = -1; i<4; i++){
         var href = getBaseURL () + 'nivel' + i +'.kml';
			  google.earth.fetchKml(ge, href, function(kmlObject) {
			        if (kmlObject)
			           ge.getFeatures().appendChild(kmlObject);
			        
			        if (kmlObject.getAbstractView() !== null)
			            ge.getView().setAbstractView(kmlObject.getAbstractView());
			  });
     	 }
         ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

         // add some layers
         ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
         ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
         // Fly to the Pentagon
         var la = ge.createLookAt('');
        // en la uns  latitud =  -38.701555; //-y aprox
        // longitud =   -62.270475;
         la.set(-38.70166, -62.26965, 
        		 90, //altura 
        		 ge.ALTITUDE_RELATIVE_TO_GROUND,
        		 45, //norte para arriba
        		 30, //tilt
        		 100); //range
         ge.getView().setAbstractView(la);
        		 
        		 
         function eventHandler(event) {
        	    var text = 'Click:';

        	    function addToMessage(append1, append2) {
        	      text += ' ' + append1 + ': ' + append2 + '\n' ;
        	    }
        	    addToMessage('latitude', event.getLatitude());
        	    addToMessage('longitude', event.getLongitude());
        	  
        	    // wrap alerts in API callbacks and event handlers
        	    // in a setTimeout to prevent deadlock in some browsers
        	    setTimeout(function() {
        	     // alert(text);
        	    }, 0);
        	  }

        	  // listen to the click event on the globe and window
        	  google.earth.addEventListener(ge.getGlobe(), 'click', eventHandler);
      }
      function failureCB(errorCode) {
      }
      function getBaseURL () {
    	   return 'http://localhost/tfc/___TFC_Devel/aulas_js_pruebas/';
    	  /* var loc = window.location;
    	    var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
    	   return pathName;*/
    	}

      google.setOnLoadCallback(init);
      

   </script>

</head>
<body>
   <div id="map3d" style="height: 600px; width: 800px;"></div>
</body>
</html>